package com.qh.yyxt.controller;

import com.qh.yyxt.pojo.entity.meeting.Meeting;
import com.qh.yyxt.service.BorrowService;
import com.qh.yyxt.service.MeetingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class MeetingController
{
    @Autowired
    private MeetingService meetingService;
    @Autowired
    private BorrowService borrowService;
    //根据id返回详细信息
    @RequestMapping("/user/getMeetingInfo")
    @ResponseBody
    public Meeting getMeetingInfo(Integer id)
    {
        return  meetingService.findInfoById(id);
    }
    //把教室都传过去
    @RequestMapping("/user/getAllMeeting")
    @ResponseBody
    public List<Meeting> getAllMeeting()
    {
        return meetingService.findAllMeeting();
    }
    //添加教室
    @RequestMapping("/admin/addMeeting")
    @ResponseBody
    public String addMeeting(String name,String site,Integer maxnum,Integer micro,Integer wireless,Integer teacup,String mes)
    {
        if(name==null||site==null||maxnum==null||micro==null||wireless==null||teacup==null||mes==null)
        {
            return "都不能为空！";
        }
        if(name.equals(""))
        {
            return "会议室名字不能为空！";
        }
        return meetingService.addMeeting(name,site,maxnum,micro,wireless,teacup,mes);
    }
    //修改教室信息
    @RequestMapping("/admin/changeMeeting")
    @ResponseBody
    public String changeMeeting(Integer id,String name,String site,Integer maxnum,Integer micro,Integer wireless,Integer teacup,String mes)
    {
        if(id==null||name==null||site==null||maxnum==null||micro==null||wireless==null||teacup==null||mes==null)
        {
            return "都不能为空！";
        }
        if(name.equals(""))
        {
            return "会议室名字不能为空！";
        }
        return meetingService.updateMeeting(id,name,site,maxnum,micro,wireless,teacup,mes);
    }
    //删除教室信息
    @RequestMapping("/admin/deleteMeeting")
    @ResponseBody
    public String deleteMeeting(int id)
    {
       if( !borrowService.findByMidAndState(id,"审批通过").isEmpty()||!borrowService.findByMidAndState(id,"待审批").isEmpty())
       {
           return "删除失败，有的会议申请处在审批通过或者待审批状态，请处理后再进行删除！";
       }
        return meetingService.deleteMeeting(id);
    }
}
